package com.yz.rabbitmq.confirm;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.ConfirmListener;
import com.yz.rabbitmq.ChannelsUtil;

import java.io.IOException;

/**
 * 描述：
 **/
public class ConfirmProducer {

    public static void main(String[] args) {
        Channel channel = ChannelsUtil.getChannel();
            try {
                //1.开启confirm消息确认
                channel.confirmSelect();
                channel.basicPublish("confirm_fanout","",null,"hello World".getBytes());
                //2.添加ConfirmListener
                channel.addConfirmListener(new ConfirmListener() {
                    @Override
                    public void handleAck(long deliveryTag, boolean multiple) throws IOException {
                        System.out.println("------ACK------");
                    }

                    @Override
                    public void handleNack(long deliveryTag, boolean multiple) throws IOException {
                        System.out.println("------NCK------");
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                //ChannelsUtil.closeChannel(channel);
            }
    }
}